import java.util.*;

/**
 * Created with IntelliJ IDEA
 * Description
 * User: 王杰
 * Date: 2025-05-24
 * Time: 15:50
 */
public class TestArrayList {
    // 洗牌算法
    public static void main7(String[] args) {

        // 1. 买 52 张牌
        CartDemo cartDemo = new CartDemo();
        List<Cart> cartList = cartDemo.buyCard();
        System.out.println(cartList);
        // 2. 洗牌
        cartDemo.shuffle(cartList);
        System.out.println(cartList);
        // 3. 3个人 每个人 轮流揭牌5张
        List<List<Cart>> ret = cartDemo.play(cartList);

        for (int i = 0; i < ret.size(); i++) {
            System.out.println(ret.get(i));
        }

        // 剩下的牌
        System.out.println(cartList);
    }

    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();

        List<Integer> list0 = new ArrayList<>();
        list0.add(1);
        ret.add(list0);

        // 从第二行开始 进行求每个元素
        for (int i = 1; i < numRows; i++) {
            // 处理第一个元素
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);

            // 中间
            List<Integer> preRow = new ArrayList<>();
            preRow = ret.get(i - 1);
            for (int j = 1; j < i; j++) {
                int val1 = preRow.get(j);
                int val2 = preRow.get(j - 1);
                curRow.add(val1 + val2);
            }

            // 尾巴
            curRow.add(1);
            ret.add(curRow);
        }

        return ret;
    }

    // 杨辉三角练习
    public static void main6(String[] args) {
        List<List<Integer>> list = new ArrayList<>();
        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list.add(list1);

        ArrayList<Integer> list2 = new ArrayList<>();
        list2.add(11);
        list2.add(21);
        list.add(list2);

        System.out.println(list);
    }
    // 题目练习
    public static void main5(String[] args) {
        String str1 = "welcome to bit";
        String str2 = "come";
        ArrayList<Character> ret = new ArrayList<>();

        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if (!str2.contains(ch + "")) {
                ret.add(ch);
            }
        }

        for (int i = 0; i < ret.size(); i++) {
            System.out.print(ret.get(i));
        }
        System.out.println();
    }
    // 遍历
    public static void main4(String[] args) {
        ArrayList<Integer> test = new ArrayList<>();
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);

        System.out.println("===使用迭代器输出 listIterator 拓展功能===");
        ListIterator<Integer> iterator3 = test.listIterator(test.size());
        while (iterator3.hasPrevious()) {
            System.out.print(iterator3.previous() + " ");
        }
        System.out.println();

        System.out.println("===使用迭代器输出 iterator===");
        Iterator<Integer> iterator = test.iterator();
        while (iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();

        System.out.println("===使用迭代器输出 listIterator===");
        ListIterator<Integer> iterator2 = test.listIterator();
        while (iterator2.hasNext()) {
            System.out.print(iterator2.next() + " ");
        }
        System.out.println();

        int size = test.size();
        System.out.println("===for循环输出===");
        for (int i = 0; i < size; i++) {
            System.out.print(test.get(i) + " ");
        }
        System.out.println();

        System.out.println("===for each循环输出===");
        for (Integer x : test) {
            System.out.print(x + " ");
        }
        System.out.println();
    }

    // subList
    public static void main3(String[] args) {
        ArrayList<Integer> test = new ArrayList<>();
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);

        List<Integer> list = test.subList(1, 3);
        System.out.println(list);

        System.out.println("======================================");

        list.set(0, 99);
        System.out.println(test); // 预期 1 2 3 4 5
        System.out.println(list); // 预期 99 3
    }
    public static void main2(String[] args) {
        ArrayList<Integer> test = new ArrayList<>();
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);
        List<Integer> list = test.subList(1, 3);
        System.out.println(list);
    }
    public static void main1(String[] args) {
        ArrayList<Integer> test = new ArrayList<>(10);
        test.add(1);
        test.add(2);
        test.add(3);
        System.out.println(test);

//         过时操作
//         test.remove(new Integer(2));
//         System.out.println(test);
    }
}
